<?php
class EditorPanelWidget extends Widget {

    public $model;
    
    public $route;
    public $htmlOptions=array();
    public $itemHtmlOptions=array();
    
    public $menu=array();
    
   
    /**
     * Initializes the widgets
     */
    public function init() {
        parent::init();
        
        $user=Yii::app()->user;
        
        if($user->isGuest || 
                !($user->isAdmin || in_array($user->id, array_filter(array($this->model->creatorId, $this->model->editorId))))
          ) return ;
        
        $this->menu = array(
            'status'=>array('label' => Lang::t('editor.panel.status', array('{status}'=>$this->model->status)), 'url' =>''),
            'edit'=>array('label' => Lang::t('editor.panel.edit'), 'url' => $this->model->editUrl),
            'delete'=>array('label' => Lang::t('editor.panel.delete'), 'url' => $this->model->deleteUrl),
        );
        
        switch($user){
            case $user->isAdmin:
                $this->menu['suspend']=array('label' => Lang::t('editor.panel.suspend'), 'url' => $this->model->editUrl);
                unset($this->menu['delete']);
                break;
        }
    }

    /**
     * Execute the widgets
     */
    public function run() {
        Yii::beginProfile(get_class($this));

        echo CHtml::openTag('ul', $this->htmlOptions);
            foreach($this->menu as $item){
                echo CHtml::openTag('li', $this->itemHtmlOptions);
                echo CHtml::link($item['label'], $item['url'], array('class'=>str_replace(' ','-',strtolower($item['label']))));
                echo CHtml::closeTag('li');
            }
        echo CHtml::closeTag('ul');
        
        Yii::endProfile(get_class($this));
    }

}//end class